package cn.com.wangluotongxin.merchants.controller;

import cn.com.wangluotongxin.common.web.AjaxResult;
import cn.com.wangluotongxin.db.pojo.PageData;
import cn.com.wangluotongxin.merchants.dto.GoodsSizeDto;
import cn.com.wangluotongxin.merchants.form.GoodsSizeForm;
import cn.com.wangluotongxin.merchants.service.IMerchantsGoodsSizeService;
import cn.com.wangluotongxin.merchants.vo.GoodsSizeVo;
import cn.com.wangluotongxin.web.utils.TenantAuthUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商户管理-商品管理-尺码 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2024-06-20
 */
@Api(tags = "商户管理-商品管理-尺码 相关接口")
@RestController
@RequestMapping("/goods/size")
public class MerchantsGoodsSizeController {

    @Autowired
    private IMerchantsGoodsSizeService goodsSizeService;

    @ApiOperation("分页")
    @GetMapping("/page")
    public AjaxResult<PageData<GoodsSizeVo>> getPage(GoodsSizeDto dto){
        IPage<GoodsSizeVo> page = goodsSizeService.getPage(dto);
        return AjaxResult.success(PageData.build(page));
    }

    @ApiOperation("列表")
    @GetMapping("/list")
    public AjaxResult<List<GoodsSizeVo>> list(String name) {
        return AjaxResult.success(goodsSizeService.getList(name));
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GoodsSizeForm form) {
        Assert.isTrue(StrUtil.isNotBlank(form.getSizeName()), "缺少名称");

        goodsSizeService.add(form, TenantAuthUtil.getTenantUser());
        return AjaxResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") Integer id) {
        goodsSizeService.delete(id);
        return AjaxResult.success();
    }

    @ApiOperation("启用/禁用")
    @PostMapping("/enabled/{id}/{isEnabled}")
    public AjaxResult enabled(@PathVariable("id") Integer id, @PathVariable("isEnabled") Integer isEnabled) {

        goodsSizeService.enabled(id, isEnabled);
        return AjaxResult.success();
    }
}